package se.webbzon.oschi01.action;

import javax.swing.AbstractAction;

import se.webbzon.oschi01.command.Command;
import se.webbzon.oschi01.command.CommandListener;
import se.webbzon.oschi01.command.CommanderAction;

public abstract class DefaultAction extends AbstractAction implements CommanderAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4167132350267122483L;
	
	private CommandListener listener = null;
	
	protected boolean performCommand(Command command) {
		if (listener == null)
			return false;
		else {
			listener.performCommand(command);
			return true;
		}
	}
	
	@Override public boolean hasListener() {
		return listener == null;
	}
	
	@Override public boolean setListener(CommandListener listener) {
		if (this.listener == null) {
			this.listener = listener;
			return true;
		} else
			return false;
	}

	@Override public boolean removeListener(CommandListener listener) {
		if (this.listener == listener) {
			this.listener = null;
			return true;
		} else
			return false;
	}

}
